package edu.luc.concordia; 

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.event.EventListenerList;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.*;

/**
 * Copyright 2008 Project Concordia
 * <p>
 * This file is part of RetailReturnSystem.
 * <p>
 * RetailReturnSystem is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <p>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <p>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.
 * <hr>
 * This class shows first screen of Retail Checkout and Return System.
 * Clerk enter initialization file name here.
 * <p>
 * @author Rashmi Pandey & Piyushaben Desai
 * @version 0.1 2008-10-10
 */
public class SystemStart extends JPanel implements ActionListener
{	
	private JTextField initializedFileField;
	
	private JButton cancelButton;	
	private JButton startButton;
	
	private JLabel initializedFileLabel;
	
	private JFrame frame;
	private EventListenerList listener = new EventListenerList();
	private ActionListener forwardListener = new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			Object[] currentListeners = listener.getListenerList();
			
			for (int i = currentListeners.length - 2; i >= 0; i -= 2) {
				if (currentListeners[i] == ActionListener.class) {
					((ActionListener) currentListeners[i + 1]).actionPerformed(e);
				}
			}
		}
	};
	public void addActionListener(ActionListener l)
	{
		listener.add(ActionListener.class, l);
	}
	
	public SystemStart()
	{
		
	}
	
	public SystemStart(JFrame frame)
	{
		this.frame = frame;
						
		JPanel displayPanel = new JPanel();
		displayPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		//File name Label 
		initializedFileLabel = new JLabel ("Enter File Name :");
		displayPanel.add(initializedFileLabel);
		
		//File name text field
		initializedFileField = new JTextField(15);
		displayPanel.add(initializedFileField);
		initializedFileField.setEditable(true);
		initializedFileField.setFocusable(true);
		
		//Button Panel
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		
		//Start Button
		startButton = new JButton("Initialize");
		startButton.addActionListener(this);
		buttonPanel.add(startButton);
		startButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
			
			ActionEvent startevent = new ActionEvent(initializedFileField, 0,ActionConstants.SYSTEM_INITIALIZE);
			forwardListener.actionPerformed(startevent);
			}
		});
		
				
		//Cancel button
		cancelButton = new JButton ("Cancel");
		cancelButton.addActionListener(this);
		buttonPanel.add(cancelButton);
		this.add(displayPanel, BorderLayout.CENTER);
		this.add(buttonPanel, BorderLayout.SOUTH);	
		
	}
	
	public void actionPerformed(ActionEvent e)
	{
					
	}
}



